﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VAdvantage.Utility;
using VAdvantage.Model;
using VAdvantage.DataBase;
using System.Data;
using System.Threading;
using VAdvantage.Classes;

namespace VAdvantage.Apps
{
    public class ViennaRoleCenter
    {
        public ViennaRoleCenter()
        {
        }

        List<KeyNamePair> _ListTab = null;

        public List<KeyNamePair> ListTab
        {
            get { return _ListTab; }
            set { _ListTab = value; }
        }

        int _RC_View_ID = 0;

        public int RC_View_ID
        {
            get { return _RC_View_ID; }
            set { _RC_View_ID = value; }
        }

        int _D_Chart_ID = 0;

        public int D_Chart_ID
        {
            get { return _D_Chart_ID; }
            set { _D_Chart_ID = value; }
        }

        int _RC_Tab_ID = 0;

        public int RC_Tab_ID
        {
            get { return _RC_Tab_ID; }
            set { _RC_Tab_ID = value; }
        }

        int _Colspan = 0;

        public int Colspan
        {
            get { return _Colspan; }
            set { _Colspan = value; }
        }
        int _Rowspan = 0;

        public int Rowspan
        {
            get { return _Rowspan; }
            set { _Rowspan = value; }
        }
        int _SeqNo = 0;

        public int SeqNo
        {
            get { return _SeqNo; }
            set { _SeqNo = value; }
        }

        private bool _EditMode = false;

        public bool EditMode
        {
            get { return _EditMode; }
            set { _EditMode = value; }
        }

        private int _FramePane_ID = 0;

        public int FramePane_ID
        {
            get { return _FramePane_ID; }
            set { _FramePane_ID = value; }
        }
        private int _ChartPane_ID = 0;

        public int ChartPane_ID
        {
            get { return _ChartPane_ID; }
            set { _ChartPane_ID = value; }
        }
        private int _TabPanel_ID = 0;

        public int TabPanel_ID
        {
            get { return _TabPanel_ID; }
            set { _TabPanel_ID = value; }
        }

        private string _PanelName;

        public string PanelName
        {
            get { return _PanelName; }
            set { _PanelName = value; }

        }

        private string _Description;
        public string Description
        {
            get { return _Description; }
            set { _Description = value; }

        }

        int _MaxValue = 0;

        public int MaxValue
        {
            get { return _MaxValue; }
            set { _MaxValue = value; }
        }
        int _MinValue = 0;

        public int MinValue
        {
            get { return _MinValue; }
            set { _MinValue = value; }
        }
        int _FontColor_ID = 0;

        public int FontColor_ID
        {
            get { return _FontColor_ID; }
            set { _FontColor_ID = value; }
        }
        int _HeaderBGColor_ID = 0;

        public int HeaderBGColor_ID
        {
            get { return _HeaderBGColor_ID; }
            set { _HeaderBGColor_ID = value; }
        }
        int _HeaderFontColor_ID = 0;

        public int HeaderFontColor_ID
        {
            get { return _HeaderFontColor_ID; }
            set { _HeaderFontColor_ID = value; }
        }
        int _BGColor_ID = 0;

        public int BGColor_ID
        {
            get { return _BGColor_ID; }
            set { _BGColor_ID = value; }
        }
        int _AD_Tab_ID = 0;

        public int AD_Tab_ID
        {
            get { return _AD_Tab_ID; }
            set { _AD_Tab_ID = value; }
        }
        int _ADUserQuery_ID = 0;

        public int ADUserQuery_ID
        {
            get { return _ADUserQuery_ID; }
            set { _ADUserQuery_ID = value; }
        }

        int _ParentKeyID = 0;
        public int ParentKeyID
        {
            get { return _ParentKeyID; }
            set { _ParentKeyID = value; }
        }



        int _KPIPaneID = 0;
        public int KPIPaneID
        {
            get { return _KPIPaneID; }
            set { _KPIPaneID = value; }
        }


        bool _IsKPI = false;
        public bool IsKPI
        {
            get;
            set;
        }

    }

    public partial class AddFramesToTab : ChildWindow
    {
        public AddFramesToTab()
        {
        }

        List<KeyNamePair> _tabList = null;
        public AddFramesToTab(List<KeyNamePair> tabList)
        {
            _tabList = tabList;
            InitializeComponent();

            vLabel1.Content = Msg.GetMsg("RoleCenterTab");
            vLabel2.Content = Msg.GetMsg("FrameName");
            for (int i = 0; i <= _tabList.Count - 1; i++)
            {
                cmbTabs.Items.Add(_tabList[i]);
            }
        }

        int _tabId = 0;
        KeyNamePair[] FinalList = null;

        void LoadFrames()
        {
            string sql = @"Select RC_ViewPane_id, Name from RC_ViewPane where IsActive = 'Y' And Ad_Client_ID = " + Envs.GetCtx().GetAD_Client_ID();
            IDataReader dr = DB.ExecuteReader(sql);
            while (dr.Read())
            {
                KeyNamePair list = new KeyNamePair(int.Parse(dr["RC_ViewPane_id"].ToString()), dr["name"].ToString());
                Dispatcher.BeginInvoke(() => cmbFrames.Items.Add(list));
            }
            dr.Close();



        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            KeyNamePair tabSelected = (KeyNamePair)cmbTabs.SelectedItem;
            KeyNamePair frameSelected = (KeyNamePair)cmbFrames.SelectedItem;
            ThreadPool.QueueUserWorkItem(delegate
            {
                X_RC_TabPanels tabPanels = new X_RC_TabPanels(Envs.GetCtx(), 0, null);
                tabPanels.SetRC_RoleCenterTab_ID(tabSelected.GetKey());
                tabPanels.SetRecord_ID(frameSelected.GetKey());
                tabPanels.SetRoleCenterPanels("1");

                if (tabPanels.Save())
                {
                    Dispatcher.BeginInvoke(delegate
                    {
                        ShowMessage.Info(Msg.GetMsg("RecordSaved"), false, "", "");
                        this.Close();
                    });
                }
                else
                    Dispatcher.BeginInvoke(delegate
                    {
                        ShowMessage.Info(Msg.GetMsg("RecordNotSaved"), false, "", "");
                    });
            });
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        public object List { get; set; }

        private void ChildWindow_Closed(object sender, EventArgs e)
        {

        }

        private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ThreadPool.QueueUserWorkItem(delegate
            {
                LoadFrames();
            });
        }
    }
}

